package com.central.scheduler.plugin.task.datax.json.reader;

import com.central.common.entity.ReaderParams;
import com.central.common.model.DatasourceInfo;
import com.central.scheduler.plugin.task.datax.json.ReaderJson;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tindy
 * @date 2022/3/10
 * @describe
 */
@Getter
@Setter
public class MysqlReaderJson implements ReaderJson {
    private List<String> column=new ArrayList<>();
    private List<Map<String,List<String>>> connection=new ArrayList<>();
    private String username;
    private String password;
    private String where;
    private String splitPk;

    public MysqlReaderJson(ReaderParams reader, DatasourceInfo readerDatasource) {
        this.column= reader.getColumn();
        this.where=reader.getWhere();
        this.splitPk=reader.getSplitPk();
        this.username=readerDatasource.getUsername();
        this.password=readerDatasource.getPassword();
        String jdbcUrl="jdbc:mysql://"+readerDatasource.getHost()+ ":" + readerDatasource.getPort() + "/"+reader.getDbName();
        String table=reader.getTbName();
        HashMap<String, List<String>> connMap = new HashMap<>();
        ArrayList<String> jdbcUrls = new ArrayList<>();
        jdbcUrls.add(jdbcUrl);
        ArrayList<String> tables = new ArrayList<>();
        tables.add(table);
        connMap.put("jdbcUrl",jdbcUrls);
        connMap.put("table",tables);
        connection.add(connMap);
    }
}
